package com.atom.app.mvvm.utils

import java.io.*

object FileUtil {
     fun readFile(filePath: String, charsetName: String = "UTF-8"): StringBuilder {
        val file = File(filePath)
        val fileContent = StringBuilder("")
        if (!file.isFile) {
            return fileContent
        }
        var reader: BufferedReader? = null
        try{
            val input = InputStreamReader(FileInputStream(file), charsetName)
            reader = BufferedReader(input)
            var line: String?
            while (reader.readLine().also { line = it } != null) {
                fileContent.append(line)
            }
        } catch (e: IOException) {
            e.printStackTrace()
        } finally {
            try {
                reader?.close()
            } catch (e: IOException) {
                e.printStackTrace()
            }
        }
        return fileContent
    }
}
